public class Demo7 {
    private static int ret;
    public static void main(String[] args) throws InterruptedException {
        Object block = new Object();

        Thread thread1 = new Thread(() -> {
            for (int i = 0; i < 5000; i++) {

                synchronized (block){
                    ret++;
                }

            }
        });
        Thread thread2 = new Thread(() -> {
            for (int i = 0; i < 5000; i++) {

                synchronized (block){
                    ret++;
                }

            }
        });
        thread1.start();
        thread2.start();
        thread1.join();
        thread2.join();
        System.out.println(ret);;
    }
}
